Error recovery method and apparatus based on a lockup mechanism

ABSTRACT

An error recovery method and apparatus, and a system are disclosed. At least two CPUs in a lockstep mode can exit the lockstep mode when an error occurs in at least one CPU, and the CPU in which the error occurs and a type of the error are determined. When the error can be recovered, the CPU in which the error occurs can be recovered according to a correctly running CPU. This helps the at least two CPUs run again at a position at which a service program is interrupted.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a continuation of International Application No.PCT/CN2020/093188, filed on May 29, 2020, which claims priority toChinese Patent Application No. 201910473113.6, filed on May 31, 2019.The disclosures of the aforementioned applications are herebyincorporated by reference in their entireties.

TECHNICAL FIELD

This application relates to the computer field, and more specifically,to an error recovery method and apparatus in the computer field.

BACKGROUND

Trends such as autonomous driving make functional security a keyindicator of an automotive industry. More and more software and hardwaresystems need to be secure. These security systems need to operatereliably to ensure personal safety, even in a case of failure oraccident. In this case, security redundancy needs to be considered at aplurality of layers, such as an overall development process, hardware,software, and an algorithm. When a partition becomes invalid, an errorcan be found timely and recovered without affecting a function ofanother partition.

To meet the foregoing security requirement, a lockstep system emerges.The lockstep system is a fault-tolerant computer system that uses alockstep mechanism, and implements the security redundancy by running asame group of operations at the same time in parallel. In the lockstepsystem, two independent central processing units (CPUs) execute a sameinstruction in a same clock cycle. An error check function is added toeach CPU, for example, error correction code (ECC) parity check. Inaddition, outputs of the two CPUs are compared through a comparator.When a comparison result is that two bits or more than two bits areinconsistent, and an error is found in one CPU after checking but theother CPU is normal after checking, lockstep is disabled. Therefore, theCPU in which an error is found after checking is stopped and the CPUthat is normal after checking works normally. If the comparison resultis that only one bit is in consistent and an error is found in only oneCPU after checking, a previous state is returned. When an error is foundin each of the two CPUs after checking or each of the two CPUs is normalafter checking, but output results of the two CPUs are inconsistent, thetwo CPUs fall out of synchronization and the system stops running. Itcan be seen that, in the existing lockstep system, when the comparisonresult is that only one bit is inconsistent and an error is found inonly one CPU after checking, the two CPUs are recovered to previoussaving states of current running states of the CPUs for rerunning. If amulti-bit error occurs, and the error cannot be corrected, the lockstepsystem exits a lockstep mode, and a service stops. Therefore, an errorrecovery capability of the existing lockstep system is relatively weak,and system reliability cannot meet a requirement of a security service.

SUMMARY

This application provides an error recovery method and apparatus, toimprove an error recovery capability of a lockstep system and improvesystem reliability.

According to a first aspect, an error recovery method is provided. Themethod includes: when a first CPU in at least two central processingunits CPUs in a lockstep mode has an error, receiving an interrupt;exiting, by the at least two CPUs, the lockstep mode in response to theinterrupt; determining a type of the error of the first CPU in which theerror occurs; and when the error is a recoverable error, performingerror recovery on the first CPU according to a state of a correctlyrunning second CPU in the at least two CPUs at a time of triggering theinterrupt. Therefore, in the solution in this embodiment of thisapplication, based on determining on an error type of a lockstep CPU,and when the error type is recoverable, the CPU in which the erroroccurs can be recovered according to a state of a CPU that runsnormally, so that the at least two CPUs run again at a position at whicha service program is interrupted. Therefore, in this embodiment of thisapplication, an error recovery capability of a lockstep system can beimproved, and system reliability can be improved.

In an embodiment, the state of the second CPU at the time of triggeringthe interrupt includes a software-visible CPU context of the second CPUat the time of triggering the interrupt, and the CPU context includes avalue of a system register and a value of a general purpose register;and the performing error recovery on the first CPU according to a stateof a correctly running second CPU in the at least two CPUs at a time oftriggering the interrupt includes: obtaining, from a memory, asoftware-visible CPU context of the second CPU at the time of triggeringthe interrupt; and updating, according to the software-visible CPUcontext of the second CPU, a software-visible CPU context of the firstCPU.

In an embodiment, the software-visible CPU context of the second CPU anddata in a cache at the time of triggering the interrupt is saved to thememory. A software-visible CPU context of the first CPU and data in acache at the time of triggering the interrupt is saved to the memory.

In an embodiment, when the at least two CPUs in the lockstep CPU exitthe lockstep mode and enter a split mode, a quantity of software-visibleCPUs changes from one to a plurality. In this case, on one hand,initialization of a memory stack of the CPU context is performed, toensure that contexts of a plurality of CPUs are stored in differentstacks. This can prevent data from being overwritten. In addition, datain a CPU L1/L2 cache is flushed to an external memory, to ensure thatdata cannot be lost when the CPU re-enters the lockstep mode. On theother hand, the at least two CPUs separately jump to an entry of anexception vector table, and synchronize an error of the CPU, to ensurethat an asynchronous error in a system can be immediately reported atthis moment, and prepare for subsequent query of an error type.

In an embodiment, the performing error recovery on the first CPUaccording to a state of a correctly running second CPU in the at leasttwo CPUs at a time of triggering the interrupt includes: obtaining, byusing the first CPU through a hardware channel between the first CPU andthe second CPU, a software-visible CPU context of the second CPU at thetime of triggering the interrupt, and updating, according to thesoftware-visible CPU context of the second CPU, a software-visible CPUcontext of the first CPU, where the CPU context includes a value of asystem register and a value of a general purpose register.

It should be noted that in some special cases, that an error occurs in aregister at which level is unknown, for example, a system suspension. Inthis case, registers of all levels can be repaired in a hardwarechannel-based manner.

In an embodiment, the method further includes: after thesoftware-visible CPU context of the first CPU is updated, respectivelyresetting software-invisible microarchitecture states of the first CPUand the second CPU, and retaining the respective software-visible CPUcontext, so that the first CPU and the second CPU re-enter the lockstepmode. In other words, an error CPU resets all software-invisiblehardware states, clears data in a CPU cache, and reservessoftware-visible states in the system register and the general register.Therefore, before the resetting, software-visible states set by the atleast two CPUs are completely the same. After the resetting,software-visible states of the at least two CPUs are still the same, andthe at least two CPUs obtain data and an instruction from the externalmemory and receive a same input instruction stream.

In an embodiment, the performing error recovery on the first CPUaccording to a state of a correctly running second CPU in the at leasttwo CPUs at a time of triggering the interrupt includes: respectivelyresetting the first CPU and the second CPU, and executing aninitialization instruction to recover a software-visible CPU context, sothat the first CPU and the second CPU re-enter the lockstep mode, wherethe initialization instruction includes a software-visible CPU contextof the second CPU at the time of triggering the interrupt, and is usedto recover a software-visible CPU context of the first CPU to thesoftware-visible CPU context of the second CPU at the time of triggeringthe interrupt, and the CPU context includes a value of a system registerand a value of a general purpose register.

In some embodiments, the first CPU and the second CPU may be reset atthe same time, and execute the initialization instruction at the sametime, so that the first CPU and the second CPU re-enter the lockstepmode. Therefore, before the resetting, software-visible states set bythe at least two CPUs are completely the same. After the resetting,software-visible states of the at least two CPUs are still the same, andthe at least two CPUs obtain data and an instruction from the externalmemory and receive a same input instruction stream.

In an embodiment, the determining a first CPU, in the at least two CPUs,in which an error occurs, and a type of the error includes: determiningthe type of the error according to an advanced configuration and powermanagement interface (ACPI) table corresponding to the first CPU, wherethe ACPI table is used to record an error found when a status registerof a reliability, availability, and serviceability (RAS) node of a CPUis polled. In this way, when an RAS error occurs in the CPU, the CPU isinterrupted, or the system is abnormal and enters an UEFI or a BIOS. TheUEFI or the BIOS traverses status registers of all RAS nodes, andrecords an error corresponding to the CPU in a memory table (namely, theAPCI table). Therefore, an ACPI driver of an operating system can parsethe table to know which node in the system has an error of which type.Alternatively, the first CPU polls a status register of an RAS node ofthe first CPU, to determine the type of the error. In this way, when anRAS error occurs in the CPU, the CPU is interrupted, or the system isabnormal. In this case, an RAS driver directly traverses statusregisters of all RAS nodes in sequence, to determine a cause of theerror, instead of obtaining the cause by querying the ACPI table.

In a possible embodiment, the second CPU may further poll a statusregister of an RAS node of the second CPU, to determine that the secondCPU runs normally.

In a possible embodiment, the second CPU may further determine,according to an ACPI table corresponding to the second CPU, that thesecond CPU runs normally.

In a possible embodiment, when the at least two CPUs enter the splitmode, each CPU may determine whether an error occurs in the CPU, anddoes not need to query the RAS node or the ACPI table. In other words,in this case, which CPU is a CPU in which an error occurs and which CPUis a CPU that runs normally may be directly determined.

In an embodiment, the receiving, by at least two CPUs in a lockstepmode, an interrupt includes: receiving, by the at least two CPUs, theinterrupt sent by an interrupt controller, and the interrupt controllersends the interrupt to the at least two CPUs when a comparator circuitdetermines that outputs of the at least two CPUs are inconsistent.

In a possible embodiment, the comparison circuit may be implemented by adedicated hardware circuit, and is not disposed on a critical path. Forexample, the comparison circuit may be disposed outside the CPU. In thisway, the comparison circuit has no impact on performance of the CPU.

In a possible implementation, the comparison circuit is a comparisoncircuit at a CPU clock cycle level. Specifically, a comparison circuitcorresponding to the lockstep CPU shares a clock source with thelockstep CPU, to ensure that the comparison circuit and the CPU are at asame frequency, and implement cycle-by-cycle data comparison. Therefore,an error can be found in time, and error recovery or other furtherprocessing can be performed as soon as possible.

In an embodiment, the outputs of the at least two CPUs include at leastone of an internal bus output of each of the at least two CPUs, anexternal bus output of each of the at least two CPUs, and an L3 cachecontrol logic output of each of the at least two CPUs.

In an embodiment, the determining a first CPU, in the at least two CPUs,in which an error occurs, and a type of the error includes:

querying a status register of an RAS node corresponding to thecomparator circuit to determine the first CPU, in the at least two CPUs,in which the error occurs and the type of the error.

In this case, when the comparator determines that the obtained outputsof the CPUs are inconsistent, an RAS interrupt may be reported, andinformation about inconsistent data of the comparison is provided in aregister of an RAS node corresponding to the comparator, for example, atleast one of an error data address, an error module, and an error type.

In an embodiment, the method further includes: stopping running the atleast two CPUs when the error is an unrecoverable error.

According to a second aspect, an error recovery apparatus is provided.The apparatus includes a first central processing unit CPU and a secondCPU.

The first CPU is configured to: receive an interrupt, where theinterrupt is triggered by an error that occurs in a first CPU when thefirst CPU and a second CPU are in a lockstep mode, exit the lockstepmode in response to the interrupt, determine a type of the error, andwhen the error is a recoverable error, perform error recovery accordingto a state of the second CPU at a time of triggering the interrupt; andthe second CPU is configured to receive the interrupt and exit thelockstep mode.

In an embodiment, the first CPU is configured to: obtain, from a memory,a software-visible CPU context of the second CPU at the time oftriggering the interrupt, and update, according to the software-visibleCPU context of the second CPU, a software-visible CPU context of thefirst CPU, where the CPU context includes a value of a system registerand a value of a general purpose register.

In an embodiment, the second CPU is further configured to save thesoftware-visible CPU context of the second CPU and data in a cache atthe time of triggering the interrupt to the memory.

In an embodiment, the first CPU is configured to: obtain, through ahardware channel between the first CPU and the second CPU, asoftware-visible CPU context of the second CPU at the time of triggeringthe interrupt, and update, according to the software-visible CPU contextof the second CPU, a software-visible CPU context of the first CPU,where the CPU context includes a value of a system register and a valueof a general purpose register.

In an embodiment, the first CPU is further configured to: after thesoftware-visible CPU context is updated, reset a software-invisiblemicroarchitecture state of the first CPU, and retain thesoftware-visible CPU context of the first CPU, so that the first CPUre-enters the lockstep mode; and the second CPU is further configuredto: after the software-visible CPU context of the first CPU is updated,reset a software-invisible microarchitecture state of the second CPU,and retain the software-visible CPU context of the second CPU, so thatthe second CPU re-enters the lockstep mode.

In an embodiment, the first CPU is configured to be reset, and after theresetting, is specifically configured to execute an initializationinstruction to recover a software-visible CPU context, so that the firstCPU re-enters the lockstep mode, where the initialization instructionincludes a software-visible CPU context of the second CPU at the time oftriggering the interrupt, and is used to recover a software-visible CPUcontext of the first CPU to the software-visible CPU context of thesecond CPU at the time of triggering the interrupt, and the CPU contextincludes a value of a system register and a value of a general purposeregister.

The second CPU is configured to be reset, and after the resetting, isconfigured to execute the initialization instruction, so that the secondCPU re-enters the lockstep mode.

In some embodiments, the first CPU and the second CPU may be reset atthe same time, and execute the initialization instruction at the sametime, so that the first CPU and the second CPU re-enter the lockstepmode.

In an embodiment, the first CPU is specifically configured to: determinethe type of the error according to an ACPI table corresponding to thefirst CPU, where the ACPI table is used to record an error found when astatus register of a reliability, availability, and serviceability RASnode of a CPU is polled; or poll a status register of an RAS node of thefirst CPU, to determine the type of the error.

In an embodiment, the first CPU is configured to receive the interruptsent by an interrupt controller, where the interrupt controller sendsthe interrupt to the first CPU and the second CPU when a comparatorcircuit determines that outputs of the first CPU and the second CPU areinconsistent; and the second CPU is configured to receive the interruptsent by the interrupt controller.

In an embodiment, the outputs of the CPUs include at least one of aninternal bus output of the CPU, an external bus output of the CPU, andan L3 cache control logic output of the CPU.

In an embodiment, the first CPU is further configured to query a statusregister of an RAS node corresponding to the comparator circuit todetermine the first CPU in which the error occurs and the type of theerror.

In an embodiment, the first CPU and the second CPU further stop runningwhen the error is an unrecoverable error.

In an embodiment, the apparatus further includes an interrupt controllerand a comparator circuit. The comparator circuit is configured to obtainoutputs of the first CPU and the second CPU, and send a first signal tothe interrupt controller when determining that the outputs of the firstCPU and the second CPU are inconsistent, where the first signal is usedto indicate the interrupt controller to send an interrupt to the firstCPU and the second CPU; and the interrupt controller sends the interruptto the first CPU and the second CPU according to the first signal.

According to a third aspect, an error recovery apparatus is provided.The apparatus includes a determining unit and a recovery unit. When anerror occurs in a first CPU in at least two central processing unitsCPUs that are in a lockstep mode, and when the at least two CPUs exitthe lockstep mode, the determining unit is configured to determine atype of the error in the first CPU; and the recovery unit is configuredto perform, when the error is a recoverable error, error recovery on thefirst CPU according to a state of a correctly running second CPU in theat least two CPUs at a time of triggering an interrupt.

In an embodiment, the recovery unit is configured to: obtain, from amemory, a software-visible CPU context of the second CPU at the time oftriggering the interrupt, and update, according to the software-visibleCPU context of the second CPU, a software-visible CPU context of thefirst CPU, where the CPU context includes a value of a system registerand a value of a general purpose register.

In an embodiment, the apparatus further includes a CPU contextmanagement unit. The CPU context management unit is configured to savethe software-visible CPU context of the second CPU and data in a cacheat the time of triggering the interrupt to the memory.

In an embodiment, the apparatus further includes an initialization unit.The initialization unit is configured to: after the first CPU and thesecond CPU are reset, execute an initialization instruction to recover asoftware-visible CPU context, so that the first CPU and the second CPUre-enter the lockstep mode, where the initialization instructionincludes a software-visible CPU context of the second CPU at the time oftriggering the interrupt, and is used to recover a software-visible CPUcontext of the first CPU to the software-visible CPU context of thesecond CPU at the time of triggering the interrupt, and the CPU contextincludes a value of a system register and a value of a general purposeregister.

In an embodiment, the determining unit is configured to: determine thetype of the error according to an advanced configuration and powermanagement interface ACPI table corresponding to the first CPU, wherethe ACPI table is used to record an error found when a status registerof a reliability, availability, and serviceability RAS node of a CPU ispolled; or poll a status register of an RAS node of the first CPU, todetermine the type of the error.

In an embodiment, the determining unit is configured to: query a statusregister of an RAS node corresponding to the comparator circuit, todetermine the first CPU, in the at least two CPUs, in which the erroroccurs and the type of the error, where the comparator circuit isconfigured to send a first signal to an interrupt controller whendetermining that outputs of the at least two CPUs are inconsistent, andthe first signal is used to indicate the interrupt controller to send aninterrupt to the at least two CPUs to trigger the at least two CPUs toexit the lockstep mode.

In an embodiment, the outputs of the at least two CPUs include at leastone of an internal bus output of each of the at least two CPUs, anexternal bus output of each of the at least two CPUs, and an L3 cachecontrol logic output of each of the at least two CPUs.

In an embodiment, the determining unit is further configured to controlthe at least two CPUs to stop running when the error is an unrecoverableerror.

According to a fourth aspect, a comparison circuit for querying an erroris provided. The comparison circuit is disposed outside at least twoCPUs in a lockstep mode, and the comparison circuit is configured to:determine that outputs of the at least two CPUs are inconsistent, andsend a first signal to an interrupt controller according to theinconsistent outputs of the at least two CPUs, where the first signal isused to indicate the interrupt controller to send an interrupt to the atleast two CPUs, and the interrupt is used to indicate that an erroroccurs in at least one of the at least two CPUs.

In an embodiment, the outputs of the at least two CPUs include at leastone of an internal bus output of each of the at least two CPUs, anexternal bus output of each of the at least two CPUs, and an L3 cachecontrol logic output of each of the at least two CPUs.

According to a fifth aspect, an error recovery apparatus is provided.The apparatus includes a module corresponding to themethod/operation/step/action according to the first aspect.

According to a sixth aspect, an error recovery apparatus is provided.The apparatus includes a processor, and the processor is configured toinvoke the program code stored to the memory, to perform some or alloperations in any manner according to the first aspect.

In the sixth aspect, the memory storing the program code may be locatedinside the error recovery apparatus (the error recovery apparatus mayfurther include a memory in addition to the processor), or may belocated outside the error recovery apparatus (the memory may be a memoryof another device). As an example, the processor may be a lockstep CPU,and the lockstep CPU includes at least two physical CPUs.

In an embodiment, the memory is a non-volatile memory.

When the error recovery apparatus includes a processor and a memory, theprocessor and the memory may be coupled together.

As an example, the error recovery apparatus may be a terminal, or may bean apparatus (for example, a chip, or an apparatus that can match and beused by a terminal) that is in the terminal and that is configured toperform error recovery. The terminal may be specifically a smartphone,an in-vehicle apparatus, a wearable device, or the like. Optionally, theforegoing in-vehicle apparatus may be a computer system that isindependent of an automobile but that can be applied to the automobile,or may be a computer system integrated into an automobile (for example,a self-driving automobile).

According to a seventh aspect, a computer-readable storage medium isprovided. The computer-readable storage medium stores program code, andthe program code includes an instruction used to perform some or alloperations in the method according to the first aspect.

Optionally, the computer-readable storage medium is located in aterminal, and the terminal may be an apparatus that can perform errorrecovery.

According to an eighth aspect, an embodiment of this applicationprovides a computer program product. When the computer program productruns on an error recovery apparatus, the error recovery apparatusperforms some or all of the operations in the method according to thefirst aspect.

According to a ninth aspect, a chip is provided. The chip includes aprocessor, and the processor is configured to perform some or alloperations in the method according to the first aspect.

BRIEF DESCRIPTION OF DRAWINGS

FIG. 1 shows an implementation form of a system according to anembodiment of this application;

FIG. 2 is a schematic diagram of a system architecture according to anembodiment of this application;

FIG. 3 shows an example of a query manner;

FIG. 4 is a schematic flowchart of an error recovery method according toan embodiment of this application;

FIG. 5 shows a specific example of lockstep manager initialization;

FIG. 6 shows an example of CPU context saving and recovery;

FIG. 7 shows an example of error correction based on a hardware channelaccording to an embodiment of this application;

FIG. 8 is a schematic flowchart of an error recovery method according toan embodiment of this application;

FIG. 9 is a schematic flowchart of an error recovery apparatus accordingto an embodiment of this application; and

FIG. 10 is a schematic flowchart of an error recovery apparatusaccording to an embodiment of this application.

DESCRIPTION OF EMBODIMENTS

First, related terms in the embodiments of this application aredescribed.

Lockstep CPU: A lockstep CPU is a logical CPU, and includes at least twophysical CPUs (which may also be referred to as CPUs), or includes atleast two physical cores. As an example, the at least two CPUs may bedisposed on one chip, or distributed on different chips. This is notlimited in this embodiment of this application. In some descriptions,the lockstep CPU may also be referred to as a lockstep logical CPU. Forease of description, an example in which one logical CPU includes atleast two CPUs is used below for description.

When the at least two CPUs in the lockstep CPU are in a lockstep mode,the at least two CPUs execute same code or a same instruction, andoutput a calculation result of one CPU. In this case, only one CPU isvisible to software, but the lockstep CPU includes at least two (forexample, a plurality of) CPUs.

Split CPU: When at least two CPUs in a lockstep CPU exit from a lockstepmode to a split mode in which the CPUs separately run normally. In thiscase, the at least two CPUs are visible to software.

It may be understood that the at least two CPUs in the lockstep modeshould have a same output result. Once output results of the at leasttwo CPUs are inconsistent, at least one CPU runs abnormally (in otherwords, an error occurs). When one CPU is faulty, the lockstep CPU isabnormal. The CPUs in the lockstep CPU need to exit the lockstep modeand enter the split mode.

CPU exception jump: When a CPU is running, if an error occurs or aninterrupt needs to be responded, the CPU jump into an entry of anexception vector table or an interrupt vector table, and then a functionis used to process the error or the interrupt. After the processing, theCPU may return to an originally interrupted position to continuerunning. As an example, when a lockstep CPU is abnormal, CPUs in thelockstep CPU jump abnormally, enter a split mode, and perform errorrecovery.

The following describes technical solutions of this application withreference to accompanying drawings.

FIG. 1 shows an implementation form of a system in platform software andhardware according to an embodiment of this application. As shown inFIG. 1, the hardware part may include a central processing unit (CPU), agraphics processing unit (GPU), a memory, and the like. The CPU includesa lockstep CPU 0, a lockstep CPU 1, a normal CPU 2, a normal CPU 3, andthe like. This is not specifically limited in this embodiment of thisapplication. The lockstep CPU may also be referred to as a locksteplogical CPU, and includes at least two CPUs (which may also be referredto as physical CPUs). As an example, one of the at least two CPUs may bereferred to as a primary CPU, and the other of the at least two CPUs maybe referred to as a secondary CPU or a redundant CPU. The software partincludes different running service programs and a software module thatmanages a hardware module. As an example, the service program is, forexample, an automotive safety integration level (ASIL)-D service program#1, an ASIL-D service program #2, an ASIL-B service program, or a commonprogram. As an example, the software module that manages the hardwaremodule may be, for example, an error manager #1 that manages thelockstep CPU 0, and an error manager #2 that manages the lockstep CPU 1.

It may be understood that, because the lockstep CPU can meet a securityrequirement, a service program having a relatively high security levelrequirement may run on the lockstep CPU, and a service program having arelatively low security level requirement may run on a normal CPU. Forexample, the ASIL-D service program #1 runs on the lockstep CPU 0, theASIL-D service program #2 runs on the lockstep CPU 2, and the ASIL-Bservice program and the common program may run on the CPU 2 or the CPU3. Applications of different security levels are isolated by using acontainer or a virtual machine, to prevent in-validness in one partitionfrom affecting running of a program in another partition.

FIG. 2 is a schematic diagram of a system architecture according to anembodiment of this application. The system architecture in thisembodiment of this application includes a hardware architecture and asoftware architecture. The hardware architecture is used to provide ahardware platform for error detection and correction, and the softwarearchitecture is used to provide an error correction solution based onthe hardware platform.

The hardware architecture may also be referred to as a hardware layer oran underlying hardware layer. The hardware layer may include at leastone lockstep CPU and an interrupt controller. The interrupt controlleris configured to perform interrupt control when an error occurs in a CPUin the lockstep CPU.

As shown in FIG. 2, the hardware layer includes a lockstep CPU 0 and alockstep CPU 1. The lockstep CPU 0 further includes a primary CPU 0 andat least one secondary CPU 0. The lockstep CPU 1 further includes aprimary CPU 1 and at least one secondary CPU 1. FIG. 2 shows only onesecondary CPU as an example, and does not constitute a limitation onthis embodiment of this application.

In an embodiment, at least one comparator (or referred to as acomparison circuit) is disposed in each lockstep CPU, and is configuredto obtain and compare outputs of at least two CPUs included in thelockstep CPU. In an example, an output of each CPU included in thelockstep CPU may be obtained and compared by using a comparator disposedoutside the lockstep CPU.

Specifically, the comparison circuit may be implemented by a dedicatedhardware circuit, and is not disposed on a critical path. For example,the comparison circuit may be disposed outside the CPU. In this way, thecomparison circuit has no impact on performance of the CPU.

In an embodiment, the comparison circuit is a comparison circuit at aCPU clock cycle level. Specifically, a comparison circuit correspondingto the lockstep CPU shares a clock source with the lockstep CPU, toensure that the comparison circuit and the CPU are at a same frequency,and implement cycle-by-cycle data comparison. Therefore, an error can befound in time, and error recovery or other further processing can beperformed as soon as possible. In an example, the at least onecomparator and the lockstep CPU may be disposed on a chip, to share theclock source with the lockstep CPU. However, this is not limited in thisembodiment of this application.

In an embodiment, the output of the CPU includes at least one of aninternal bus output of each of the at least two CPUs, an external busoutput of each CPU, and an L3 cache control logic output (L3 CTRL) ofeach CPU. As an example, the internal bus output of the CPU is, forexample, an L1 cache of the CPU, and the external bus output of the CPUis, for example, an L2 cache (L2 cache) of the CPU.

In an embodiment of this application, an L3 CTRL, namely, a redundant L3CTRL corresponding to the secondary CPU may be added. In an example, asshown in FIG. 2, L3 cache control logic of the lockstep CPU 0 includes,for example, L3_CTRL0, L3_RAM, and L3_CTRL0′, and L3 cache control logicof the lockstep CPU 1 includes, for example, L3_CTRL1, L3_RAM, andL3_CTRL1′. This is not limited in this embodiment of this application.

As an example, as shown in FIG. 2, the lockstep CPU 0 is used as anexample. A CPU internal output comparator 0 may be configured to comparean internal bus output of the primary CPU 0 with an internal bus outputof the at least one secondary CPU 0. A CPU external output comparator 0may be configured to compare an external bus output of the primary CPU 0with an external bus output of the at least one secondary CPU 0. An L3cache control logic output comparator 0 may be configured to compare anL3 cache control logic output (L3_CTRL0) of the primary CPU 0 with an L3cache control logic output (L3_CTRL0′) of the at least one secondary CPU0.

It should be noted that the CPU internal output comparator may bedisposed outside the CPU, and obtains an internal bus output of the CPUby using a data line. This is not limited in this embodiment of thisapplication.

It should be noted that the hardware layer in FIG. 2 is merely used asan example, and constitutes no limitation on this application.

For example, in an embodiment of this application, one lockstep CPU maybe provided with one or two of a CPU internal output comparator, a CPUexternal output comparator, and an L3 cache control logic outputcomparator. For another example, different lockstep CPUs may usedifferent comparator setting manners. For example, the lockstep CPU 0 isprovided with only the CPU internal output comparator 0, and thelockstep CPU 1 is provided with only a CPU external output comparator 1.

In a specific example, the CPU external output comparator may be set asa first-level comparison circuit, and the L3 cache control logic outputcomparator may be set as a second-level comparison circuit, but the CPUinternal output comparator is not set. In other words, data output by aninternal bus of the CPU is not compared. In this way, one level ofcomparison circuit can be reduced. In this case, when an error insidethe CPU is transmitted to outside of the CPU, the error can be foundedby a comparison circuit outside the CPU.

For another example, in an embodiment of this application, one lockstepCPU may include two physical CPUs, or include three physical CPUs.

In a possible embodiment, when finding that outputs of the at least twoCPUs in the lockstep mode are inconsistent, a comparator (for example,any one of the foregoing comparators) may send a signal to an interruptcontroller, where the signal is used to indicate the interruptcontroller to send an interrupt to the at least two CPUs. Afterreceiving the signal, the interrupt controller sends the interrupt tothe lockstep CPU. The interrupt indicates that the at least two CPUs areabnormal. When the at least two CPUs in the lockstep CPU receive theinterrupt, the at least two CPUs exit the lockstep mode, that is, entera split mode. In the split mode, the comparator does not work.

In a possible embodiment, in the split mode, an L3_CTRL corresponding toa primary CPU in the lockstep CPU works, and a redundant L3_CTRLcorresponding to a secondary CPU in the lockstep CPU is in a gated_offstate. In this case, requests of all CPUs (including the primary CPU andthe secondary CPU) in the lockstep CPU are sent to the L3_CTRL in theworking state, then are converted by the L3_CTRL, and are output to theL3_RAM. As an example, a request sent by the CPU is, for example, aread/write request, a query request, a replacement request. This is notlimited in this embodiment of this application.

The software architecture may also be referred to as a software layer.As shown in FIG. 2, the software layer mainly includes a lockstepmanager, a reliability, availability, and serviceability (RAS) errormanager, and a health monitoring module. The lockstep manager isconfigured to manage at least two CPUs in a lockstep CPU. The RAS errormanager is used to determine a CPU in which an error occurs and a typeof the error when the error occurs in a CPU in the lockstep CPU. Thehealth monitoring module is responsible for performing decisionprocessing on the type of the error.

As an example, the lockstep manager may include a lockstep configurator,a split mode manager, a CPU context manager, an error querier andcorrector, and a reset-sync operator.

The lockstep configurator sets at least two physical CPUs in a computersystem as one lockstep logical CPU, and sets a quantity of locksteplogical CPUs in the system.

The split mode manager manages a lockstep exception vector table and aninterrupt processing function. When a comparator finds that data outputby the at least two CPUs in the lockstep CPU is inconsistent, aninterrupt controller sends an interrupt to the at least two CPUs, andthe at least two CPUs enter a split mode from a lockstep mode. In thiscase, the at least two CPUs in the split mode separately jump to anentry of the exception vector table, to invoke the CPU context managerand the interrupt processing function.

In a possible embodiment, when the at least two CPUs enter the splitmode, each CPU may determine whether an error occurs in the CPU. Inother words, in this case, that which CPU is a CPU in which an erroroccurs and which CPU is a CPU that runs normally may be determined.

The CPU context manager stores, when the at least two CPUs exit thelockstep mode, a software-visible CPU context and data in an L1/L2 cacheto an L3 cache or different stacks in a memory, to prepare forsubsequent error correction. Herein, the software-visible CPU contextincludes CPU states in a kernel mode and a user mode, namely, data of asystem register and data of a general purpose register that arecorresponding to the CPU.

The error querier and corrector can be invoked by an interruptprocessing function. In an example, when the CPU enters the split modeand the CPU in which the error occurs is determined, the error querierand corrector may query an RAS error manager corresponding to the CPU inwhich the error occurs, to determine a type of the error of the CPU inwhich the error occurs. In another example, when the CPU enters thesplit mode and the CPU in which the error occurs is not determined, theerror querier and corrector may query an RAS error manager correspondingto each CPU, to determine the CPU in which the error occurs and a typeof the error.

In an embodiment of this application, the error type includes arecoverable error and an unrecoverable error. When it is determined thatthe error type of the CPU is an unrecoverable error, the healthmonitoring module is notified of performing decision processing on theCPU in which the error occurs, for example, bringing the CPU in whichthe error occurs offline. When it is determined that the error type ofthe CPU is a recoverable error, the error querier and corrector correctsthe CPU in which the error occurs.

The reset-sync operator enables the at least two physical CPUs in thesplit mode to re-enter the lockstep mode. The reset-sync operator may beimplemented in a hardware manner, or may be implemented in a softwaremanner. This is not limited in this embodiment of this application.

The RAS-error manager may include an error parser in an advancedconfiguration and power management interface (ACPI) mode, and an errorquerier in a non-ACPI mode.

As an example, the RAS error manager includes one or more RAS nodes, andeach RAS node is corresponding to one or more status registers, and thestatus register configured to store various types of errors that occurin the CPU.

An error parser in the ACPI mode can perform error query in the ACPImode. Specifically, the error parser may query an error state of the CPUby using an ACPI table. When an RAS error occurs in the CPU, the CPU isinterrupted, or a system is abnormal and enters a unified extensiblefirmware interface (UEFI) or a basic input/output system (BIOS). TheUEFI or the BIOS traverses status registers of all RAS nodes, andrecords an error corresponding to the CPU in a memory table (namely, theAPCI table). An ACPI driver of an operating system can parse the tableto know which node in the system has an error of which type.

An error querier in the non-ACPI mode can perform error query in thenon-ACPI mode. As an example, in FIG. 3, a memory management unit (MMU),an L1 data (L1 data, L1 D for short) cache, an L1 indicator (L1I) cache,an L3 cache, and an L2 cache each have one RAS node. When an RAS erroroccurs in the CPU, the CPU is interrupted, or the system is abnormal. Inthis case, an RAS driver directly traverses status registers of all RASnodes in sequence, to determine a cause of the error, instead ofobtaining the cause by querying the ACPI table.

It should be noted that in this embodiment of this application, the ACPImode may be preferentially used to query the error. If no error is foundin this mode, the non-ACPI mode may be used to query the error. This isbecause, for a producer error in the RAS node, the RAS register recordsthe error, but the system does not report the error. An exception isreported on a consumer side only when the CPU consumes error data. Inthis case, there is a possible that the error is not recorded in theACPI table. In this case, the non-ACPI mode needs to be used to poll thestatus registers of the all RAS nodes to determine the error type.

It should be noted that the producer error refers that an entitygenerates an error, and the error is a producer error for the entity.This type of error is not triggered immediately after being generated,but is reported only during consumption. For example, the memorygenerates an error. When the memory generates the error, the memory doesnot proactively report the error. The error is triggered only whenanother component read the error.

In an embodiment, one or more RAS nodes may further be disposed for acomparator corresponding to the lockstep CPU. For example, one RAS nodeis disposed for each of the CPU internal output comparator 0, the CPUexternal output comparator 0, and the L3 cache control logic outputcomparator 0. This is not limited in this embodiment of thisapplication. In this case, when the comparator determines that theobtained outputs of the CPUs are inconsistent, an RAS interrupt may bereported, and information about inconsistent data of the comparison isprovided in a register of an RAS node corresponding to the comparator,for example, at least one of an error data address, an error module, andan error type. The error module includes, for example, an L1 cachecontroller, an L2 cache controller, and an L3 controller.

In addition, names of the foregoing functions or modules in thisembodiment of this application are merely examples. In specificimplementation, the names of the functions or modules in the systemarchitecture shown in FIG. 2 may alternatively be other names. This isnot specifically limited in this embodiment of this application.

FIG. 4 is a schematic flowchart of an error recovery method according toan embodiment of this application. The method shown in FIG. 4 may beperformed by the system in FIG. 1, or may be performed by the system inFIG. 2. However, this embodiment of this application is not limitedthereto. It should be understood that FIG. 4 shows steps or operationsof a service processing method. However, these steps or operations aremerely examples. Other operations or variants of the operations in FIG.4 may alternatively be performed in this embodiment of this application.In addition, the operations in FIG. 4 may be performed in a sequencedifferent from that shown in FIG. 4, and possibly, not all theoperations in FIG. 4 need to be performed.

401: Perform lockstep manager initialization.

As an example, the lockstep manager initialization includes: resourceconfiguration initialization, exception vector table initialization,interrupt processing function initialization, and the like. This is notlimited in this embodiment of this application. Optionally, RAS errormanager initialization may further be performed.

FIG. 5 shows a specific example of the lockstep manager initialization.As shown in FIG. 5, in a phase before the lockstep managerinitialization, a configuration file may be read.

Then, the resource configuration initialization, the exception vectortable initialization, the interrupt processing function initializationare performed.

During the resource configuration initialization, two or more adjacentphysical CPUs are selected to form a group of lockstep logical CPUsbased on a service requirement. For example, when one lockstep CPU isrequired to run a task with a high safety level, during the resourceconfiguration initialization, a physical CPU 0 and a physical CPU 1 maybe configured as a group of lockstep logical CPUs to run a serviceprogram of the task.

The exception vector table initialization is initialization of a memorystack of a CPU context when a lockstep CPU enters a split mode,synchronize an error and manage data consistency, and process aninterrupt. When the at least two CPUs in the lockstep CPU exit alockstep mode and enter the split mode, a quantity of software-visibleCPUs changes from one to a plurality. In this case, on one hand,initialization of a memory stack of the CPU context is performed, toensure that contexts of a plurality of CPUs are stored in differentstacks. This can prevent data from being overwritten. On the other hand,the at least two CPUs separately jump to an entry of an exception vectortable, and synchronize an error of the CPU, to ensure that anasynchronous error in a system can be immediately reported at thismoment, and prepare for subsequent query of an error type. In addition,data in a CPU L1/L2 cache is flushed to an external memory, to ensurethat data cannot be lost when the CPU re-enters the lockstep mode.

The interrupt processing function initialization can process aninterrupt, for example, an interrupt generated when an error occurs in aCPU in a lockstep CPU. As an example, a software layer invokes aninterrupt processing function by using the entry of the exception vectortable, and then the interrupt processing function invokes an errorquerier and corrector to query the error, and performs correspondingcorrection according to the error type.

After the resource configuration initialization, the exception vectortable initialization, and the interrupt processing functioninitialization are completed, a phase after lockstep core managementmodule initialization is entered.

Then, the lockstep manager initialization ends.

402: Determine that outputs of the at least two CPUs in the lockstepmode are inconsistent.

In an embodiment, an output of each of the at least two CPUs included inthe lockstep CPU may be obtained by using a comparison circuit disposedoutside the lockstep CPU, and then the comparison circuit determineswhether the outputs of the at least two CPUs are consistent.Specifically, for the comparison circuit, refer to the description inFIG. 2. For brevity, details are not described herein again.

When determining that the outputs of the at least two CPUs in thelockstep mode are inconsistent, the comparison circuit sends a signal toan interrupt controller, and the interrupt controller sends an interruptto the CPU according to the signal. In this case, the at least two CPUsenter the split mode from the lockstep mode. The at least two CPUs inthe split mode separately jump to the entry of the interrupt vectortable, to synchronize the error of the CPU. Then, 403 and 404 areperformed.

403: Save and manage the CPU context.

As an example, the at least two physical CPUs in the split mode releaseCPU contexts corresponding to the at least two physical CPUs. Because atleast one of the CPU contexts of the at least two CPUs is incorrect, theat least two CPU contexts and the data in the cache need to be refreshedto different stack addresses in the memory.

As an example, FIG. 6 shows an example of CPU context saving andrecovery. As shown in FIG. 6, after a lockstep CPU 0′ enters a splitmode, a CPU 0 and a CPU 1 in the lockstep CPU 0′ separately jump to aninterrupt request (IRQ) entry. Then, a context of the CPU 0 is stored ina stack 0 in a memory, and a context of the CPU 1 is stored in a stack 1in a memory. After the error query is performed, that which CPU in theCPU 0 and the CPU 1 is a correct CPU, and which CPU in the CPU 0 and theCPU 1 is an error CPU can be determined. Then, when the error is arecoverable error, the error is corrected according to a result of theerror query. For example, a state of the error CPU may be set accordingto a context of the normal CPU stored to the memory. For example, whenan error occurs in the CPU 0, and the CPU 1 runs correctly, the contextstored in the stack 1 is restored to the CPU 0, to perform errorcorrection on the CPU 0. Then, the two CPUs can re-enter the lockstepmode.

404: Perform the error query.

Specifically, 404 may be executed by the error querier and corrector.The error querier and corrector can send query information to an RASerror manager, and the RAS error manager can perform the error query. Asan example, the RAS error manager performs the error query in an ACPImode and a non-ACPI mode. Specifically, for the ACPI mode and thenon-ACPI mode, refer to the foregoing description. For brevity, detailsare not described herein again.

In an embodiment, an RAS node corresponding to a comparator may bequeried, to determine a CPU in which an error occurs and a type of theerror, and another RAS node does not need to be polled. In this case, alockstep error may be considered as a common RAS error. The error querymay be performed by reading a register of an RAS node corresponding tothe comparator provided by hardware. The ACPI mode or the non-ACPI modemay be used to poll an RAS error node of the comparator. Because theregister includes at least one of an error data address, an errormodule, an error type, and the like. Therefore, the error type can bedetermined by reading the register of the RAS node corresponding to thecomparator. As an example, the lockstep error may refer to an error thatthe outputs of the at least two CPUs are inconsistent when the lockstepCPU is in the lockstep mode.

As an example, the recoverable error includes an error of anon-uncontainable error (UC) type, an error of the non-UC type whosequantity of occurrences does not exceed a preset threshold, a systemsuspension, or the like. This is not limited in this embodiment of thisapplication. As an example, the unrecoverable error may include at leastone of an error of a UC type, an error of the non-UC type whose quantityof occurrences exceeds a preset threshold, and an error of an unknowntype. This is not limited in this embodiment of this application.

In some possible embodiments, for the uncontainable error type or theunknown error type, a health monitoring module may be notified ofperforming system health monitoring. In other words, 405 is performed.When the quantity of occurrences of the error of the non-UC type exceedsthe preset threshold, the health monitoring module may be notified ofperforming system health monitoring. In other words, 405 is performed.For the error of the non-UC type, if the quantity of occurrences of theerror does not exceed the preset threshold, error recovery may beperformed by using software, as shown in 406. When the CPU system issuspended, if the error is not propagated, error recovery can beperformed by using a hardware channel, as shown in 407.

In some embodiments, when the lockstep CPU includes the two CPUs, andwhen the comparator determines that data output by the two physical CPUsis inconsistent, the RAS node corresponding to the comparator may beused to determine which CPU has an error and which type of error occurs.

In some embodiments, when the lockstep CPU includes three or morephysical CPUs, and when the comparator determines that data output bythe three or more physical CPUs is inconsistent, a CPU in which an erroroccurs may be determined according to a principle of determining onefrom more than one. Herein, the determining one from more than one meansthat when an output result of one of the at least three CPUs isinconsistent with output results of the other CPUs, it may be determinedthat an error occurs in this CPU. In this case, in a possible manner,the error CPU may be brought offline, and at least two other CPUs mayenter the lockstep mode to continue running. Alternatively, in anotherpossible manner, the RAS node corresponding to the comparator may beused to determine which CPU has an error and which type of error occurs,and then determine, according to the type of the error, whether toperform recovery on the CPU in which the error occurs.

405: The health monitoring module performs system health monitoring.

Specifically, the health monitoring module may bring the error CPUoffline, or control all CPUs in the lockstep CPU to stop running. Forexample, in an automatic driving scenario, the health monitoring modulemay notify a system of exiting an automatic driving module, so that amicro controller unit (MCU) takes over to perform emergency braking.

406: Perform recovery by using the software.

Specifically, because the context of the correct CPU is flushed from theL1/L2 cache to the memory at the entry of the exception vector table, inthis case, the context of the correct CPU may be recovered into theerror CPU, to perform recovery on the error CPU.

It should be noted that software repair is usually used in a register ata common level, for example, an EL0-level register in an ARM64architecture, an E1-level register, a RING0-level register in an X86architecture, or a RING3-level register. Generally, an error permissionlevel of the CPU in which the error occurs may be determined byperforming the error query in step 404.

407: Recover the error CPU by using the hardware channel.

Specifically, the error CPU may be synchronized according to a state ofthe correct CPU. In this case, the correct CPU may synchronize, throughthe hardware channel between the correct CPU and the error CPU, thesoftware-visible CPU context of the correct CPU to the error CPU. FIG. 7shows an example of error correction based on a hardware channelaccording to an embodiment of this application.

For the error CPU, 701A to 704A are performed, and for the correct CPU,701B to 704B are performed.

701A: Reset the error CPU, that is, reset a microarchitecture state ofthe CPU, to perform single-core recovery of the error CPU. Herein, thesingle-core recovery means that recovery is performed on the error CPU,but recovery is not performed on the correct CPU.

702A: After the single-core recovery, the error CPU enters a recoverymode, and notifies the correct CPU of entering the recovery mode at thesame time. As an example, the error CPU may notify, in an interruptmanner or in another manner, the correct CPU of entering the recoverymode. This is not limited in this embodiment of this application.

In addition, in the recovery mode, the error CPU may obtain asoftware-visible state of the correct CPU by using the hardware channel,and perform recovery according to the software-visible state of thecorrect CPU. As an example, the hardware channel may be a data channelbetween the correct CPU and the error CPU.

703A: After the state of the error CPU is recovered, the error CPU andthe correct CPU enter a reset-sync state at the same time. For 703A,refer to the description of 408.

704A: After the reset-sync is completed, all CPUs participating in thelockstep re-enter the lockstep mode. For 704A, refer to the descriptionof 409.

701B: When the error CPU is reset, the correct CPU is in a spin waitstate. In the spin wait state, the correct CPU waits for notificationfrom the error CPU of entering the recovery mode. As an example, theerror CPU may notify, in an interrupt manner or in another manner, thecorrect CPU of entering the mode. This is not limited in this embodimentof this application.

702B: After entering the recovery mode, the correct CPU sends asoftware-visible state in a register of the correct CPU to the error CPUby using the hardware channel, to perform recovery on the error CPU.

703B: After transmission of the software-visible state is completed, thecorrect CPU and the error CPU enter the reset-sync state at the sametime. For 703B, refer to the description of 408.

704B: After the reset-sync is completed, all CPUs participating in thelockstep re-enter the lockstep mode. For 704B, refer to the descriptionof 409.

It should be noted that in some special cases, that an error occurs in aregister at which level is unknown, for example, a system suspension. Inthis case, registers of all levels can be repaired in a hardwarechannel-based manner. In this case, because a quantity of registers thatneed to be recovered is large, a recovery speed is slower than that ofsoftware recovery.

408: Enter the reset-sync.

After a software-visible state inside an error CPU core is recovered,the correct CPU performs the reset-sync, that is, resets an internalmicroarchitecture. In a possible implementation, an error CPU resets allsoftware-invisible hardware states, clears data in a CPU cache, andreserves software-visible states in the system register and the generalregister. Based on this, the reset-sync is different from conventionalCPU reset, and the reset-sync is not complete reset. Therefore, arequired time is relatively short, for example, may be dozens of CPUclock cycles.

In an embodiment, after the at least two CPUs are reset, aninitialization instruction may be executed to recover a software-visibleCPU context, so that the at least two CPUs re-enter the lockstep mode,where the initialization instruction includes a software-visible CPUcontext of the second CPU at the time of triggering the interrupt, andis used to recover a software-visible CPU context of the first CPU tothe software-visible CPU context of the second CPU at the time oftriggering the interrupt, and the CPU context includes a value of asystem register and a value of a general purpose register. In animplementation, the initialization instruction may be executed by aninitialization unit.

In a possible embodiment, the at least two CPUs participating in thelockstep are reset to a position at which the software pre-places aninitialization instruction, where the initialization instructionincludes a CPU PC pointer and a system register (namely, a value of thesystem register or data) of the foregoing correct CPU at an interruptmoment. After the resetting, the at least two CPUs execute theinitialization instruction at the same time.

Before the reset-sync is performed, the software-visible states set bythe at least two physical CPUs are completely the same. After thereset-sync is performed, the software-visible states of the at least twophysical CPUs are still the same, and the at least two CPUs obtain dataand an instruction from the external memory and receive a same inputinstruction stream.

409: The lockstep CPU continues to run at a previous exit position.

After the reset-sync is performed, in one case, microarchitecture statesof all CPUs participating in the lockstep each are an initial stateafter the resetting. The software-visible state is a state before aservice is interrupted. In another case, all CPUs participating in thelockstep execute the initialization instruction at the same time, andtherefore the lockstep CPU can continue to run from a position at whicha service program is interrupted previously.

In addition, the comparator corresponding to the lockstep CPU continuesto perform cycle-by-cycle comparison on the at least two physical CPUsin the lockstep CPU.

Therefore, in the embodiments of this application, the at least two CPUsin the lockstep mode can exit the lockstep mode when an error occurs inat least one CPU, and the CPU in which the error occurs and a CPU thatruns normally are determined. Based on this, when the error can berecovered, the CPU in which the error occurs can be recovered based on aCPU that runs normally. This helps the at least two CPUs run again at aposition at which a service program is interrupted. Therefore, in theembodiments of this application, an error recovery capability of alockstep system can be improved, and system reliability can be improved.

FIG. 8 is a schematic flowchart of an error recovery method according toan embodiment of this application. As an example, the method may beperformed by the system shown in FIG. 1 or FIG. 2. The method includes810 to 830.

810: At least two CPUs in a lockstep mode receive an interrupt, wherethe interrupt is used to indicate that an error occurs in at least oneof the at least two CPUs.

820: The at least two CPUs exit the lockstep mode in response to theinterrupt.

830: Determine a first CPU, in the at least two CPUs, in which an erroroccurs, and a type of the error.

840: When the error is a recoverable error, perform error recovery onthe first CPU according to a state of a correctly running second CPU inthe at least two CPUs at a time of triggering the interrupt.

Therefore, in the embodiments of this application, the at least two CPUsin the lockstep mode can exit the lockstep mode when an error occurs inat least one CPU, and the CPU in which the error occurs and the type ofthe error are determined. Based on this, when the error can berecovered, the CPU in which the error occurs can be recovered based on aCPU that runs normally. This helps the at least two CPUs run again at aposition at which a service program is interrupted. Therefore, in theembodiments of this application, an error recovery capability of alockstep system can be improved, and system reliability can be improved.

It should be noted that there may be one or more first CPUs and one ormore second CPUs.

As an example, a state of the CPU may include a software-visible stateand/or a software-invisible hardware state of the CPU. Thesoftware-visible state, also referred to as a CPU context, includes avalue (or data) of a general purpose register and a value (or data) of asystem register. The software-invisible hardware state may also bereferred to as a software-invisible microarchitecture state, and may beexecuted on the processor.

In a possible embodiment, the at least two CPUs stop running when theerror is an unrecoverable error.

In some embodiments, the performing error recovery on the first CPUaccording to a state of the correctly running second CPU in the at leasttwo CPUs at the time of triggering interrupt includes:

obtaining, from a memory, a software-visible CPU context of the secondCPU at the time of triggering the interrupt, and updating, according tothe software-visible CPU context of the second CPU, a software-visibleCPU context of the first CPU, where the CPU context includes a value ofa system register and a value of a general purpose register.

In some embodiments, the second CPU is further configured to save thesoftware-visible CPU context of the second CPU and data in a cache atthe time of triggering the interrupt to the memory. Optionally, thefirst CPU may save the software-visible CPU context of the first CPU anddata in a cache at the time of triggering the interrupt to the memory.

In some embodiments, the performing error recovery on the first CPUaccording to a state of the correctly running second CPU in the at leasttwo CPUs at the time of triggering interrupt includes:

obtaining, through a hardware channel between the first CPU and thesecond CPU, a software-visible CPU context of the second CPU at the timeof triggering the interrupt, and updating, according to thesoftware-visible CPU context of the second CPU, a software-visible CPUcontext of the first CPU, where the CPU context includes a value of asystem register and a value of a general purpose register.

It should be noted that in some special cases, that an error occurs in aregister at which level is unknown, for example, a system suspension. Inthis case, registers of all levels can be repaired in a hardwarechannel-based manner.

In some embodiments, the method further includes: after thesoftware-visible CPU context of the first CPU is updated, respectivelyresetting software-invisible microarchitecture states of the first CPUand the second CPU, and retaining the respective software-visible CPUcontext, so that the first CPU and the second CPU re-enter the lockstepmode. In other words, an error CPU resets all software-invisiblehardware states, clears data in a CPU cache, and reservessoftware-visible states in the system register and the general register.

Therefore, before the resetting, software-visible states set by the atleast two CPUs are completely the same. After the resetting,software-visible states of the at least two CPUs are still the same, andthe at least two CPUs obtain data and an instruction from the externalmemory and receive a same input instruction stream.

In some embodiments, the performing error recovery on the first CPUaccording to a state of the correctly running second CPU in the at leasttwo CPUs at the time of triggering interrupt includes:

respectively resetting the first CPU and the second CPU, and executingan initialization instruction to recover a software-visible CPU context,so that the first CPU and the second CPU re-enter the lockstep mode,where the initialization instruction includes a software-visible CPUcontext of the second CPU at the time of triggering the interrupt, andis used to recover a software-visible CPU context of the first CPU tothe software-visible CPU context of the second CPU at the time oftriggering the interrupt, and the CPU context includes a value of asystem register and a value of a general purpose register.

Therefore, before the resetting, software-visible states set by the atleast two CPUs are completely the same. After the resetting,software-visible states of the at least two CPUs are still the same, andthe at least two CPUs obtain data and an instruction from the externalmemory and receive a same input instruction stream.

In some embodiments, the determining a first CPU, in the at least twoCPUs, in which an error occurs, and a type of the error includes:

determining, by the first CPU, the type of the error according to anadvanced configuration and power management interface ACPI tablecorresponding to the first CPU, where the ACPI table is used to recordan error found when a status register of a reliability, availability,and serviceability RAS node of a CPU is polled. In this way, when an RASerror occurs in the CPU, the CPU is interrupted, or the system isabnormal and enters an UEFI or a BIOS. The UEFI or the BIOS traversesstatus registers of all RAS nodes, and records an error corresponding tothe CPU in a memory table (namely, the APCI table). Therefore, an ACPIdriver of an operating system can parse the table to know which node inthe system has an error of which type.

Alternatively, the first CPU polls a status register of an RAS node ofthe first CPU, to determine the type of the error. In this way, when anRAS error occurs in the CPU, the CPU is interrupted, or the system isabnormal. In this case, an RAS driver directly traverses statusregisters of all RAS nodes in sequence, to determine a cause of theerror, instead of obtaining the cause by querying the ACPI table.

In an embodiment, the second CPU may further poll a status register ofan RAS node of the second CPU, to determine that the second CPU runsnormally.

In an embodiment, the second CPU may further determine, according to anACPI table corresponding to the second CPU, that the second CPU runsnormally.

In an embodiment, when the at least two CPUs enter the split mode, eachCPU may determine whether an error occurs in the CPU, and does not needto query the RAS node or the ACPI table. In other words, in this case,that which CPU is a CPU in which an error occurs and which CPU is a CPUthat runs normally may be directly determined.

In some embodiments, the receiving, by at least two CPUs, an interruptincludes:

receiving, by the at least two CPUs, the interrupt sent by an interruptcontroller, and the interrupt controller sends the interrupt to the atleast two CPUs when a comparator circuit determines that outputs of theat least two CPUs are inconsistent.

In some embodiments, the outputs of the at least two CPUs include atleast one of an internal bus output of each of the at least two CPUs, anexternal bus output of each of the at least two CPUs, and an L3 cachecontrol logic output of each of the at least two CPUs.

In some embodiments, the determining a first CPU, in the at least twoCPUs, in which an error occurs, and a type of the error includes:

querying a status register of an RAS node corresponding to thecomparator circuit to determine the first CPU, in the at least two CPUs,in which the error occurs and the type of the error.

In this case, when the comparator determines that the obtained outputsof the CPUs are inconsistent, an RAS interrupt may be reported, andinformation about inconsistent data of the comparison is provided in aregister of an RAS node corresponding to the comparator, for example, atleast one of an error data address, an error module, and an error type.

The error recovery method shown in FIG. 8 can implement each process ofthe error recovery method corresponding to the foregoing methodembodiment. For details, refer to the foregoing descriptions. To avoidrepetition, details are not described herein again.

The foregoing describes in detail the error recovery method in theembodiments of this application with reference to FIG. 1 to FIG. 8. Thefollowing describes in detail an error recovery apparatus in theembodiments of this application with reference to FIG. 9. It should beunderstood that the error recovery apparatus in FIG. 9 can perform thesteps of the error recovery method in the embodiments of thisapplication. When the error recovery apparatus shown in FIG. 9 isdescribed below, repeated descriptions are properly omitted.

FIG. 9 is a schematic block diagram of an error recovery apparatus 900according to an embodiment of this application.

The apparatus 900 shown in FIG. 9 includes a lockstep CPU 910, and thelockstep CPU 910 includes a first CPU 9110 and a second CPU 9120.

The first CPU 9110 is configured to: receive an interrupt, where theinterrupt is triggered by an error that occurs in the first CPU 9110when the first CPU 9110 and the second CPU 9120 are in a lockstep mode;

exit the lockstep mode in response to the interrupt, and determine atype of the error; and

when the error is a recoverable error, perform error recovery accordingto a state of the second CPU 9120 at the time of triggering theinterrupt.

The second CPU 9120 is configured to receive the interrupt and exit thelockstep mode.

In some embodiments, the first CPU 9110 is specifically configured to:

obtain, from a memory, a software-visible CPU context of the second CPU9120 at the time of triggering the interrupt, and update, according tothe software-visible CPU context of the second CPU 9120, asoftware-visible CPU context of the first CPU 9110, where the CPUcontext includes a value of a system register and a value of a generalpurpose register.

In some embodiments, the second CPU 9120 is further configured to savethe software-visible CPU context of the second CPU 9120 and data in acache at the time of triggering the interrupt to the memory.

In some embodiments, the first CPU 9110 is specifically configured to:

obtain, through a hardware channel between the first CPU 9110 and thesecond CPU 9120, a software-visible CPU context of the second CPU 9120at the time of triggering the interrupt, and update, according to thesoftware-visible CPU context of the second CPU 9120, a software-visibleCPU context of the first CPU 9110, where the CPU context includes avalue of a system register and a value of a general purpose register.

In some embodiments, the first CPU 9110 is further configured to: afterthe software-visible CPU context is updated, reset a software-invisiblemicroarchitecture state of the first CPU 9110, and retain thesoftware-visible CPU context of the first CPU 9110, so that the firstCPU 9110 re-enters the lockstep mode; and

the second CPU 9120 is further configured to: after the software-visibleCPU context of the first CPU 9110 is updated, reset a software-invisiblemicroarchitecture state of the second CPU 9120, and retain thesoftware-visible CPU context of the second CPU 9120, so that the secondCPU 9120 re-enters the lockstep mode.

In some embodiments, the first CPU 9110 is specifically configured to bereset, and after the resetting, is specifically configured to execute aninitialization instruction to recover a software-visible CPU context, sothat the first CPU 9110 re-enters the lockstep mode, where theinitialization instruction includes a software-visible CPU context ofthe second CPU 9120 at the time of triggering the interrupt, and theinitialization instruction is used to recover a software-visible CPUcontext of the first CPU 9110 to the software-visible CPU context of thesecond CPU 9120 at the time of triggering the interrupt, where the CPUcontext includes a value of a system register and a value of a generalpurpose register.

The second CPU 9120 is specifically configured to be reset, and afterthe resetting, is specifically configured to execute the initializationinstruction, so that the second CPU 9120 re-enters the lockstep mode.

In some embodiments, the first CPU and the second CPU may be reset atthe same time, and execute the initialization instruction at the sametime, so that the first CPU and the second CPU re-enter the lockstepmode.

In some embodiments, the first CPU 9110 is specifically configured to:

determine the type of the error according to an advanced configurationand power management interface ACPI table corresponding to the first CPU9110, where the ACPI table is used to record an error found when astatus register of a reliability, availability, and serviceability RASnode of a CPU is polled; or

poll a status register of an RAS node of the first CPU 9110, todetermine the type of the error.

In some embodiments, the first CPU 9110 is specifically configured toreceive the interrupt sent by an interrupt controller, where theinterrupt controller sends the interrupt to the first CPU 9110 and thesecond CPU 9120 when a comparator circuit determines that outputs of thefirst CPU 9110 and the second CPU 9120 are inconsistent.

The second CPU 9120 is specifically configured to receive the interruptsent by the interrupt controller.

In some embodiments, the first CPU 9110 is further configured to:

query a status register of an RAS node corresponding to the comparatorcircuit to determine the first CPU 9110 in which the error occurs andthe type of the error.

In some embodiments, the first CPU 9110 and the second CPU 9120 furtherstop running when the error is an unrecoverable error.

In some embodiments, the apparatus 900 may further include the interruptcontroller and the comparison circuit.

The comparator circuit is configured to obtain outputs of the first CPU9110 and the second CPU 9120, and send a first signal to the interruptcontroller when determining that the outputs of the first CPU 9110 andthe second CPU 9120 are inconsistent, where the first signal is used toindicate the interrupt controller to send an interrupt to the first CPU9110 and the second CPU 9120.

The interrupt controller sends the interrupt to the first CPU 9110 andthe second CPU 9120 according to the first signal.

In an embodiment, the system may further include a storage unit 920. Ina possible manner, the storage unit 920 is configured to store aninstruction. Optionally, the storage unit 920 may also be configured tostore data or information. The storage unit 920 may be implemented byusing a memory.

In a possible embodiment, the first CPU 9110 and the second CPU 9120 maybe configured to execute the instruction stored in the storage unit 920,so that the apparatus 900 implements the foregoing error recoverymethod.

Further, the first CPU 9110, the second CPU 9120, and the storage unit920 may communicate with each other by using an internal connectionpath, to transfer a control signal and/or a data signal. For example,the storage unit 920 is configured to store a computer program, and thefirst CPU 9110 and the second CPU 9120 may be configured to invoke thecomputer program from the storage unit 920 and run the computer program,to complete the foregoing error recovery method. The storage unit 920may be integrated into the lockstep CPU 910, or may be disposedseparately from the lockstep CPU 910.

The memory may be one or more of the following types: a flash memory, ahard disk type memory, a micro multimedia card memory, a card memory(for example, an SD or an XD memory), a random access memory (RAM), astatic random access memory (SRAM), a read-only memory (ROM), anelectrically erasable programmable read-only memory (EEPROM), aprogrammable read-only memory (PROM), a magnetic memory, a magneticdisk, or an optical disc. For example, the memory may store a computerprogram (the computer program is a program corresponding to the errorrecovery method in the embodiments of this application). When theprocessing unit executes the computer program, the processing unit canperform the error recovery method in the embodiments of thisapplication.

The memory further stores data other than the computer program. Forexample, the memory may store data in a processing process of the errorrecovery method in this application.

The apparatus 900 shown in FIG. 9 can implement each process of theerror recovery method corresponding to the foregoing method embodiment.Specifically, for the apparatus 900, refer to the foregoingdescriptions. To avoid repetition, details are not described hereinagain.

FIG. 10 is a schematic block diagram of an error recovery apparatus 1000according to an embodiment of this application. The apparatus 1000includes a determining unit 1010 and a recovery unit 1020.

When an error occurs in a first CPU in at least two central processingunits CPUs that are in a lockstep mode, and when the at least two CPUsexit the lockstep mode, the determining unit 1010 is configured todetermine a type of the error in the first CPU; and

the recovery unit 1020 is configured to perform, when the error is arecoverable error, error recovery on the first CPU according to a stateof the correctly running second CPU in the at least two CPUs at a timeof triggering an interrupt.

In some embodiments, the recovery unit 1020 is specifically configuredto:

obtain, from a memory, a software-visible CPU context of the second CPUat the time of triggering the interrupt, and update, according to thesoftware-visible CPU context of the second CPU, a software-visible CPUcontext of the first CPU, where the CPU context includes a value of asystem register and a value of a general purpose register.

In some embodiments, the apparatus further includes a CPU contextmanagement unit. The CPU context management unit is configured to savethe software-visible CPU context of the second CPU and data in a cacheat the time of triggering the interrupt to the memory.

In some embodiments, the apparatus further includes an initializationunit. The initialization unit is configured to: after the first CPU andthe second CPU are reset, execute an initialization instruction torecover a software-visible CPU context, so that the first CPU and thesecond CPU re-enter the lockstep mode, where the initializationinstruction includes a software-visible CPU context of the second CPU atthe time of triggering the interrupt, and is used to recover thesoftware-visible CPU context of the first CPU to the software-visibleCPU context of the second CPU at the time of triggering the interrupt,and the CPU context includes a value of a system register and a value ofa general purpose register.

In some embodiments, the determining unit 1010 is specificallyconfigured to:

determine the type of the error according to an advanced configurationand power management interface ACPI table corresponding to the firstCPU, where the ACPI table is used to record an error found when a statusregister of a reliability, availability, and serviceability RAS node ofa CPU is polled; or

poll a status register of an RAS node of the first CPU, to determine thetype of the error.

In some embodiments, the determining unit 1010 is specificallyconfigured to:

query a status register of an RAS node corresponding to the comparatorcircuit, to determine the first CPU in which the error occurs and thetype of the error, where the comparator circuit is configured to send afirst signal to an interrupt controller when determining that outputs ofthe at least two CPUs are inconsistent, and the first signal is used toindicate the interrupt controller to send an interrupt to the at leasttwo CPUs to trigger the at least two CPUs to exit the lockstep mode.

In some embodiments, the outputs of the at least two CPUs include atleast one of an internal bus output of each of the at least two CPUs, anexternal bus output of each of the at least two CPUs, and an L3 cachecontrol logic output of each of the at least two CPUs.

In some embodiments, the determining unit 1010 is further configured tocontrol the at least two CPUs to stop running when the error is anunrecoverable error.

The error recovery apparatus 1000 shown in FIG. 10 can implement acorresponding process of the error recovery method corresponding to theforegoing method embodiment. Specifically, for the error recoveryapparatus 1000, refer to the foregoing descriptions. To avoidrepetition, details are not described herein again.

As an example, the error recovery apparatus may be a terminal, or may bean apparatus (for example, a chip, or an apparatus that can match and beused by a terminal) that is in the terminal and that is configured toperform error recovery. The terminal may be specifically a smartphone,an in-vehicle apparatus, a wearable device, or the like. Optionally, theforegoing in-vehicle apparatus may be a computer system that isindependent of an automobile but that can be applied to the automobile,or may be a computer system integrated into an automobile (for example,a self-driving automobile).

An embodiment of this application further provides a computer-readablestorage medium. The computer-readable storage medium stores programcode, and the program code includes an instruction used to perform someor all operations in the method according to any one of the foregoingembodiments.

In an embodiment, the computer-readable storage medium is located in aterminal, and the terminal may be an apparatus that can perform errorrecovery.

An embodiment of this application further provides a computer programproduct. When the computer program product runs on an error recoveryapparatus, the error recovery apparatus performs some or all of theoperations in the method according to any one of the foregoingembodiments.

An embodiment of this application further provides a chip. The chipincludes a processor, and the processor is configured to perform some orall operations in the method according to any one of the foregoingembodiments.

The embodiments in this application may be separately or jointly used.This is not limited herein.

It should be understood that descriptions such as “first” and “second”in the embodiments of this application are merely used for indicatingand distinguishing between described objects, do not show a sequence, donot indicate that a quantity of devices is specifically limited in theembodiments of this application, and cannot constitute any limitation onthe embodiments of this application.

It should be understood that sequence numbers of the foregoing processesdo not mean execution sequences in various embodiments of thisapplication. The execution sequences of the processes should bedetermined according to functions and internal logic of the processes,and should not be construed as any limitation on the implementationprocesses of the embodiments of this application.

A person of ordinary skill in the art may be aware that, in combinationwith the examples described in the embodiments disclosed in thisspecification, units and algorithm steps may be implemented byelectronic hardware or a combination of computer software and electronichardware. Whether the functions are performed by hardware or softwaredepends on particular applications and design constraint conditions ofthe technical solutions. A person skilled in the art may use differentmethods to implement the described functions for each particularapplication, but it should not be considered that the implementationgoes beyond the scope of this application.

It may be clearly understood by a person skilled in the art that, forthe purpose of convenient and brief description, for a detailed workingprocess of the foregoing system, apparatus, and unit, refer to acorresponding process in the foregoing method embodiments, and detailsare not described herein again.

In the several embodiments provided in this application, it should beunderstood that the disclosed system, apparatus, and method may beimplemented in other manners. For example, the described apparatusembodiment is merely an example. For example, division into units ismerely logical function division and may be other division in actualimplementation. For example, a plurality of units or components may becombined or integrated into another system, or some features may beignored or may not be performed. In addition, the displayed or discussedmutual couplings or direct couplings or communication connections may beimplemented by using some interfaces. The indirect couplings orcommunication connections between the apparatuses or units may beimplemented in electronic, mechanical, or other forms.

The units described as separate parts may or may not be physicallyseparate, and parts displayed as units may or may not be physical units,may be located in one position, or may be distributed on a plurality ofnetwork units. Some or all of the units may be selected according toactual requirements to achieve the objectives of the solutions of theembodiments.

In addition, functional units in the embodiments of this application maybe integrated into one processing unit, or each of the units may existalone physically, or two or more units are integrated into one unit.

When the functions are implemented in the form of a software functionalunit and sold or used as an independent product, the functions may bestored in a computer-readable storage medium. Based on such anunderstanding, the technical solutions of this application essentially,or the part contributing to the prior art, or some of the technicalsolutions may be implemented in a form of a software product. Thesoftware product is stored in a storage medium, and includes severalinstructions for instructing a computer device (which may be a personalcomputer, a server, or a network device) to perform all or some of thesteps of the methods described in the embodiments of this application.The foregoing storage medium includes: any medium that can store programcode, such as a USB flash drive, a removable hard disk, a read-onlymemory (ROM), a random access memory (RAM), a magnetic disk, or anoptical disc.

The foregoing descriptions are merely specific implementations of thisapplication, but are not intended to limit the protection scope of thisapplication. Any variation or replacement readily figured out by aperson skilled in the art within the technical scope disclosed in thisapplication shall fall within the protection scope of this application.Therefore, the protection scope of this application shall be subject tothe protection scope of the claims.

What is claimed is:
 1. An error recovery method, comprising: receivingan interrupt triggered by an error that occurs in a first centralprocessing unit (CPU), when the first CPU and a second CPU are operatingin a lockstep mode; exiting, by the first CPU, the lockstep mode inresponse to the interrupt; determining a type of the error; and inresponse to determining that the error is a recoverable error,performing error recovery on the first CPU according to a state of thesecond CPU that is correctly running at a time of triggering theinterrupt, including: obtaining, through a hardware channel between thefirst CPU and the second CPU, a software-visible CPU context of thesecond CPU at the time of triggering the interrupt, and updating,according to the software-visible CPU context of the second CPU, asoftware-visible CPU context of the first CPU, wherein thesoftware-visible CPU context of the second CPU comprises a value of asystem register and a value of a general purpose register.
 2. The methodaccording to claim 1, further comprising: after the software-visible CPUcontext of the first CPU is updated, resetting a respectivesoftware-invisible microarchitecture state of the first CPU and thesecond CPU, and retaining the respective software-visible CPU context ofthe first CPU and the second CPU, so that the first CPU and the secondCPU re-enter the lockstep mode.
 3. The method according to claim 1,wherein determining a type of the error comprises: determining the typeof the error according to an advanced configuration and power managementinterface (ACPI) table corresponding to the first CPU, wherein the ACPItable is used to record an error found when a status register of areliability, availability, and serviceability (RAS) node of a CPU ispolled; or polling a status register of an RAS node of the first CPU todetermine the type of the error.
 4. The method according to claim 1,wherein the interrupt is sent by an interrupt controller, and theinterrupt controller sends the interrupt to the first CPU and the secondCPU when a comparator circuit determines that outputs of the first CPUand the second CPU are inconsistent.
 5. The method according to claim 4,wherein the output of each of the first CPU and the second CPU comprisesat least one of an internal bus output of the corresponding CPU, anexternal bus output of the corresponding CPU, or an L3 cache controllogic output of the corresponding CPU.
 6. The method according to claim4, wherein determining a type of the error comprises: querying a statusregister of an RAS node corresponding to the comparator circuit todetermine the type of the error.
 7. The method according to claim 1,further comprising: stopping running the first CPU and the second CPUwhen the error is an unrecoverable error.
 8. The method according toclaim 1, wherein the recoverable error is a non-uncontainable error or asystem suspension.
 9. An error recovery apparatus, comprising: a firstcentral processing unit (CPU); and a second CPU, wherein the first CPUis configured to: receive an interrupt triggered by an error that occursin the first CPU when the first CPU and the second CPU are operating ina lockstep mode; exit the lockstep mode in response to the interrupt;determine a type of the error; and when the error is a recoverableerror, perform error recovery according to a state of the second CPU ata time of triggering the interrupt; and the second CPU is configured toreceive the interrupt and exit the lockstep mode; the first CPU isfurther configured to: obtain, through a hardware channel between thefirst CPU and the second CPU, a software-visible CPU context of thesecond CPU at the time of triggering the interrupt, and update,according to the software-visible CPU context of the second CPU, asoftware-visible CPU context of the first CPU, wherein the CPU contextcomprises a value of a system register and a value of a general purposeregister.
 10. The apparatus according to claim 9, wherein the first CPUis further configured to: after the software-visible CPU context isupdated, reset a software-invisible microarchitecture state of the firstCPU, and retain the software-visible CPU context of the first CPU, sothat the first CPU re-enters the lockstep mode; and the second CPU isfurther configured to: after the software-visible CPU context of thefirst CPU is updated, reset a software-invisible microarchitecture stateof the second CPU, and retain the software-visible CPU context of thesecond CPU, so that the second CPU re-enters the lockstep mode.
 11. Theapparatus according to claim 9, wherein the first CPU is configured to:determine the type of the error according to an advanced configurationand power management interface (ACPI) table corresponding to the firstCPU, wherein the ACPI table is used to record an error found when astatus register of a reliability, availability, and serviceability (RAS)node of a CPU is polled; or poll a status register of an RAS node of thefirst CPU to determine the type of the error.
 12. The apparatusaccording to claim 9, wherein the interrupt is sent by an interruptcontroller, and the interrupt controller sends the interrupt to thefirst CPU and the second CPU when a comparator circuit determines thatoutputs of the first CPU and the second CPU are inconsistent.
 13. Theapparatus according to claim 12, wherein the output of each of the firstCPU and the second CPU comprises at least one of an internal bus outputof the corresponding CPU, an external bus output of the correspondingCPU, and an L3 cache control logic output of the corresponding CPU. 14.The apparatus according to claim 12, wherein the first CPU is furtherconfigured to: query a status register of an RAS node corresponding tothe comparator circuit to determine the first CPU in which the erroroccurs and the type of the error.
 15. The apparatus according to claim9, further comprising an interrupt controller and a comparator circuit,wherein the comparator circuit is configured to obtain outputs of thefirst CPU and the second CPU and send a first signal to the interruptcontroller to request the interrupt controller to send an interrupt tothe first CPU and the second CPU, in response to determining that theoutputs of the first CPU and the second CPU are inconsistent; and theinterrupt controller sends the interrupt to the first CPU and the secondCPU according to the first signal.
 16. The apparatus according to claim9, wherein the recoverable error is a non-uncontainable error or asystem suspension.
 17. An error recovery method, comprising: receivingan interrupt triggered by an error that occurs in a first centralprocessing unit (CPU), when the first CPU and a second CPU are operatingin a lockstep mode; exiting, by the first CPU, the lockstep mode inresponse to the interrupt; determining a type of the error; and inresponse to determining that the error is a recoverable error,performing following operations: obtaining, from a memory, asoftware-visible CPU context of the second CPU at the time of triggeringthe interrupt, and updating, according to the software-visible CPUcontext of the second CPU, a software-visible CPU context of the firstCPU, wherein the software-visible CPU context of the second CPUcomprises a value of a system register and a value of a general purposeregister, resetting a respective software-invisible microarchitecturestate of the first CPU and the second CPU, and retaining the respectivesoftware-visible CPU context of the first CPU and the second CPU, sothat the first CPU and the second CPU re-enter the lockstep mode. 18.The method according to claim 17, wherein the recoverable error is anon-uncontainable error or a system suspension.
 19. The method accordingto claim 17, wherein determining a type of the error comprises:determining the type of the error according to an advanced configurationand power management interface (ACPI) table corresponding to the firstCPU, wherein the ACPI table is used to record an error found when astatus register of a reliability, availability, and serviceability (RAS)node of a CPU is polled; or polling a status register of an RAS node ofthe first CPU to determine the type of the error.
 20. The methodaccording to claim 17, wherein an output of each of the first CPU andthe second CPU comprises at least one of an internal bus output of thecorresponding CPU, an external bus output of the corresponding CPU, oran L3 cache control logic output of the corresponding CPU.